package com.fs.web.yz.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.web.base.enums.CodeEnum;
import com.fs.web.base.utils.ApplicationUtils;
import com.fs.web.base.utils.PageHeper;
import com.fs.web.base.vo.DataGrid;
import com.fs.web.base.vo.JsonResponse;
import com.fs.web.base.vo.SysPath;
import com.fs.common.pojo.Recipes;
import com.fs.web.yz.service.IRecipesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 食谱 前端控制器
 * </p>
 *
 * @author ACE
 * @since 2019-08-02
 */
@Slf4j
@Controller
@RequestMapping("/console/recipes/rewrite")
public class RecipesController {

    @Autowired
    private IRecipesService recipesService;

    public String index(Model model){
//        model.addAttribute()
        return SysPath.BACK_PATH.concat("/role/index");
    }

    public JsonResponse list(HttpServletRequest request){
        try {
            Map<String, Object> map = ApplicationUtils.getRequestDatas();
            Page page = PageHeper.pageRequest(request);
            Page<Recipes> list = recipesService.findList(page, map);
            return JsonResponse.success(DataGrid.gridBuilder(list));
        }catch (Exception e){
            log.error(e.getMessage(), e);
            return JsonResponse.error(CodeEnum.EX999);
        }
    }

}
